﻿using Microsoft.AspNetCore.Mvc;
using MyTodoApi.Context;
using MyTodoApi.Services;
using Shared.ToDo.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MyTodoApi.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class UserController : Controller
    {
        private readonly IUserService userService;

        public UserController(IUserService userService)
        {
            this.userService = userService;
        }

        [HttpGet]
        public async Task<ApiResponse> GetByIdAsync(int id) => await userService.GetById(id);

        [HttpGet]
        public async Task<ApiResponse> GetAllAsync() => await userService.GetAsync();

        [HttpPost]
        public async Task<ApiResponse> AddAsync([FromBody] UserDto user) => await userService.AddAsync(user);

        [HttpPost]
        public async Task<ApiResponse> UpdateAsync([FromBody] UserDto user) => await userService.UpdateAsync(user);

        [HttpDelete]
        public async Task<ApiResponse> DeleteAsync(int id) => await userService.Delete(id);

    }
}
